package controllers

import (
	"057dg/models"
	"github.com/astaxie/beego"
	// "github.com/astaxie/beego/context"
	"github.com/astaxie/beego/orm"
)

type CompanyController struct {
	beego.Controller
}

func (this *CompanyController) Get() {
	this.Layout = "layout/layout.html"
	this.Data["Website"] = "beego.me"
	this.Data["Email"] = "astaxie@gmail.com"
	this.Data["IsLogin"] = checkAccount(this.Ctx)
	this.TplNames = "company/index.html"
	o := orm.NewOrm()
	var comlist []models.Company
	o.QueryTable(new(models.Company)).All(&comlist)
	this.Data["comlist"] = comlist
}

func (this *CompanyController) Detail() {
	this.Data["Website"] = "beego.me"
	this.Data["Email"] = "astaxie@gmail.com"
	this.TplNames = "company/detail.html"

	id, _ := this.GetInt("id")
	o := orm.NewOrm()
	company := models.Company{Id: id}
	o.Read(&company)
	this.Data["company"] = company

}

func (this *CompanyController) Save() {
	dosubmit := this.GetString("dosubmit")
	if dosubmit == "true" {
		this.Data["json"] = 200
		this.ServeJson()
		return
	}
	this.TplNames = "account/company.html"
}
